
package ch.hearc.meteo.imp.afficheur.real.vue.atome;

import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

import ch.hearc.meteo.imp.afficheur.real.JFrameStationMeteo;
import ch.hearc.meteo.imp.afficheur.real.moo.StationMeteoElement;

public class JPanelStationMeteoListElement extends JPanel
	{

	/*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/

	public JPanelStationMeteoListElement(StationMeteoElement stationMeteoElement)
		{
		this.stationMeteoElement = stationMeteoElement;

		geometry();
		control();
		apparence();
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Public							*|
	\*------------------------------------------------------------------*/

	public void refresh()
		{
		repaint();
		}

	public boolean isSelected()
		{
		return checkBox.isSelected();
		}

	/*------------------------------*\
	|*				Set				*|
	\*------------------------------*/

	public void setIsSelected(boolean isSelected)
		{
		checkBox.setSelected(isSelected);
		}

	@Override
	public void setEnabled(boolean isEnabled)
		{
		checkBox.setEnabled(isEnabled);
		}

	/*------------------------------*\
	|*				Get				*|
	\*------------------------------*/
	public StationMeteoElement getStationMeteoElement()
		{
		return this.stationMeteoElement;
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	private void apparence()
		{
		checkBox.setFocusable(false);
		this.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, JFrameStationMeteo.COLOR_P1));
		}

	private void control()
		{
		checkBox.addActionListener(new ActionListener()
			{

				@Override
				public void actionPerformed(ActionEvent event)
					{
					stationMeteoElement.getPanelStationMeteoCarteElement().setIsSelected(checkBox.isSelected());
					JFrameStationMeteo.getInstance().refreshSelectedStations(stationMeteoElement);
					}
			});
		}

	private void geometry()
		{
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		checkBox = new JCheckBox(stationMeteoElement.getAffichageOption().getTitre());
		checkBox.setMargin(new Insets(0, 0, 0, 20));

		this.add(checkBox);

		}

	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/

	//Input
	private StationMeteoElement stationMeteoElement;

	//Tools
	private JCheckBox checkBox;
	}
